﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Web.Configuration;

public partial class PersonPhones : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void txtListaj_Click(object sender, EventArgs e)
    {
        ListView1.Visible = false;
        OleDbConnection conn = new OleDbConnection(WebConfigurationManager.ConnectionStrings["forestryDB"].ConnectionString);
        OleDbCommand cmd = new OleDbCommand("SELECT ssn, p_fname, p_lname FROM Person WHERE ssn LIKE @ssn OR p_fname LIKE @p_fname OR p_lname LIKE @p_lname", conn);
        cmd.Parameters.AddWithValue("@ssn", txtMaticenBroj.Text + "%");
        cmd.Parameters.AddWithValue("@p_fname", txtIme.Text + "%");
        cmd.Parameters.AddWithValue("@p_lname", txtPrezime.Text + "%");

        using (conn)
        {
            conn.Open();
            OleDbDataReader rd = cmd.ExecuteReader();
            int i = 1;
            ListBox1.Items.Clear();
            while (rd.Read())
            {
                ListBox1.Items.Add(new ListItem(i + ". " + rd["ssn"].ToString() + " " + rd["p_fname"].ToString() + " " + rd["p_lname"].ToString(), rd["ssn"].ToString()));
                
                i++;
            }
        }
    }

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListView1.Visible = true;
    }
}